// pages/person/Quiz-index/Quiz-first/Quiz-first.js
const app = getApp();
Page({
  data: {
    competitionId: null, // 用于存储接收到的比赛 ID
    Quiz: [], // 用于存储该期比赛的详细内容
  },

  onLoad(options) {
    // 从 URL 参数中获取 competitionId
    const competitionId = options.competitionId;
    // 将 competitionId 设置到 data 中
    this.setData({
      competitionId: competitionId
    });
    // 调用方法根据 competitionId 获取该期比赛的详细内容
    this.getCompetitionDetails(competitionId);
  },

  getCompetitionDetails(competitionId) {
    wx.request({
      url: `${app.globalData.baseUrl}/api/competition/${competitionId}`, 
      method: 'GET',
      success: (res) => {
        if (res.statusCode === 200) {
          console.log('获取到的比赛详细信息:', res.data.data);
          this.setData({
            Quiz: res.data.data, 
          });
        } else {
          console.error('获取比赛详细信息失败，状态码:', res.statusCode);
          wx.showToast({ title: '加载失败', icon: 'error' });
        }
      },
      fail: (err) => {
        console.error('获取比赛详细信息失败:', err);
        wx.showToast({ title: '网络错误', icon: 'error' });
      }
    });
  },
  onShareAppMessage() {
        return {
          title: '军事理论答题活动',
          path: '/pages/person/Quiz-index/Quiz-index'
        };
      },
        startQuiz(e) {
      // 直接从 this.data 中获取 competitionId
      const id = this.data.competitionId;
      wx.navigateTo({
        url: `/pages/person/Quiz-index/Quiz/Quiz?competitionId=${id}`
      });
    },
    Quizrank(){
      wx.navigateTo({
        url: '/pages/person/Quiz-index/Quiz-rank/Quiz-rank',
      })
    }
});